package rdb.model;

import java.util.ArrayList;
import java.util.List;

public class ListObject extends BaseObject {
    private List<byte[]> value;

    public ListObject(BaseObject baseObject, List<byte[]> val) {
        super(baseObject);
        value = val;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("list: ");
        for (byte[] bs : value) {
            sb.append(new String(bs)).append(" ");
        }
        sb.append("\n");
        return sb.toString();
    }

    @Override
    public Object getValue() {
        return value;
    }

    @Override
    public String[] getCmdLines() {
        String[] ret = new String[2+value.size()];
        int i = 0;
        ret[i++] = "rpush";
        ret[i++] = getKey();
        for (byte[] val : value) {
            ret[i++] = new String(val);
        }
        return ret;
    }
}
